﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.IO;
using ProjManagSolution.pmMyWebService;

namespace ProjManagSolution
{
    public class Session
    {
        //private static String userInfo ;
        private IsolatedStorageSettings apps = IsolatedStorageSettings.ApplicationSettings;

        public void InsertProjectInfo(project projectInfo)
        {
            apps["projectinfo"] = projectInfo;
        }

        public void InsertUserInfo(user userInfo , string role)
        {
            apps["userinfo"] = userInfo;
            apps["role"] = role;
        }

        public void InsertUserEmail(string input)
        {
            apps["useremail"] = input;
            //userInfo = username;

            //using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            //{
            //    using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream("userInfo.txt", System.IO.FileMode.Create, isf))
            //    {
            //        using (StreamWriter sw = new StreamWriter(isfs))
            //        {
            //            sw.Write(username);
            //            sw.Close();
            //        }
            //    }

            //}
        }

        public string GetUserEmail()
        {
            return (string)apps["useremail"];
            //string result = String.Empty;

            //using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            //{
            //    using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream("userInfo.txt", System.IO.FileMode.Open, isf))
            //    {
            //        using (StreamReader sr = new StreamReader(isfs))
            //        {
            //            string lineOfData = String.Empty;
            //            while ((lineOfData = sr.ReadLine()) != null)
            //                result += lineOfData;
            //        }
            //    }

            //}
        }

        public user GetUserInfo()
        {
            return (user)apps["userinfo"];
        }

        public project GetProjectInfo()
        {
            return (project)apps["projectinfo"];
        }

        public string GetUserRole()
        {
            return (string)apps["role"];
        }

        public void ClearUserInfo()
        {
            apps.Remove("userinfo");
            apps.Remove("role");
            apps.Remove("useremail");
        }

        public void ClearProjectInfo()
        {
            apps.Remove("projectinfo");
        }

        public void ClearAllInfo()
        {
            ClearUserInfo();
            ClearProjectInfo();
        }
    }
}
